home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gnulib / libsrc98.zoo / sleep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-09  |  774 b   |  41 lines

  1. /* sleep -- sleep for a specified number of seconds */
  2. /* usleep -- sleep for a specified number of microSecond */
  3. /* written by Eric R. Smith and placed in the public domain */
  4.  
  5. #include <time.h>
  6. #include <unistd.h>
  7.  
  8. /* clock() has a rez of CLOCKS_PER_SEC ticks/sec */
  9.  
  10. #define USEC_PER_TICK (1000000L / ((unsigned long)CLOCKS_PER_SEC))
  11. #define    USEC_TO_CLOCK_TICKS(us)    ((us) / USEC_PER_TICK )
  12.  
  13. unsigned int
  14. sleep(n)
  15.     unsigned int n;
  16. {
  17.     unsigned long    stop;
  18.  
  19.     stop = clock() + n * CLOCKS_PER_SEC;
  20.     while (clock() < stop)
  21.         ;
  22.  
  23.     return 0;
  24. }
  25.  
  26. /*
  27.  * Sleep for usec microSeconds 
  28.  * the actual suspension time can be arbitrarily longer
  29.  *
  30.  */
  31. void
  32. usleep(usec)
  33. unsigned long usec;
  34. {
  35.     unsigned long    stop;
  36.  
  37.     stop = clock() + USEC_TO_CLOCK_TICKS(usec);
  38.     while (clock() < stop)
  39.         ;
  40. }
  41.